All Questions
220 questions
5votes
2answers
349views
PHP Fisher-Yates shuffle with random_int
The PHP manual states that the regular shuffle() function isn't cryptographically secure, but that random_int() is. I thought, ...
2votes
2answers
102views
delete multidimentional array value in php
I made a program that converts JSON to a PHP array and checks every value of the multidimensional array with a loop and if a value matches certain values then it deletes that key and value and ...
2votes
1answer
127views
function to group data by parent branches
I wrote this function to take database output like from PDO's fetchAll(PDO::FETCH_ASSOC) and turn it into a tree. For small datasets it works well. However, when ...
4votes
3answers
1kviews
Filter an array, but remove the filtered elements
I needed a PHP function that would filter values from one array into a new one, while also removing those values from the original array. After looking through the docs, I didn't see any such function,...
0votes
1answer
89views
PHP assign values within in_array
What is a more efficient way of writing this sample code? Its purpose is to create a variable for days of the week based on a numerical value. This data is obtained from user input checkboxes. If the ...
4votes
2answers
186views
Modify a WordPress loop to show posts of certain categories, based on user roles
I've got some code that works as intended, but I have a feeling that it's messy. This code is modifying a wordpress loop and the goal is to check the roles of the current user and show posts of ...
1vote
1answer
159views
implode on two level dimensions array
I have an array like this ...
3votes
1answer
140views
a php function to check a 'deep' array value
I've just coded a little function to check and get a deep array value. Basically, I need to return the value or null if it's not set or does not exists, or in general not useful for databases records. ...
2votes
2answers
626views
remove ALL duplicate elements from an array
I have this code to remove duplicates (all occurrences) from an associative array, does PHP have methods to do this ? Or is there a way to improve the code ? I looked for array_unique, array_search, ...
3votes
3answers
607views
Find common timeslots for consecutive days
Imagine you want to reserve a classroom over several days. You get a schedule, from the school, telling you when a certain classroom is still free. To make it easy for your students, you want to ...
2votes
2answers
2kviews
Sort array of dates
I have this array with dates. All the dates are checked before creating the array with preg_match and check_dates. GoodDates ( ...
1vote
1answer
2kviews
PHP Group associative Array duplicates and make subarrays of different values
I have this type of table: ...
1vote
2answers
102views
Check URL for keywords [closed]
I'm looking at improving my PHP knowledge and wondering if anybody has any tips on improving and optimising my function below? ...
2votes
1answer
325views
PHP update multidimensional array values from same path multidmensional array
I need to update a multidimensional array by same key paths of a multidimensional array. I think my code can be better condensed : ...
2votes
0answers
54views
editing the array I've included instead of editing the file of included array php
In order to reduce time complexity, instead of loading (and then dumping to use it for later) the whole file into an array (It would be O(n) with n=number of lines), I have saved it as array into a ...